//
//  BNDHomeController.m
//  BNDAnnouncement
//
//  Created by pie on 2022/3/27.
//  Copyright © 2022 LaKa. All rights reserved.
//

#import "BNDHomeController.h"
#import "BNDOfficeDocVc.h"
#import "BNDChooseCompanyView.h"
#import "BNDHomeCardHelper.h"
#import "BNDOfficeDocVc.h"
#import "BNDOfficeDocHandle.h"


@interface BNDHomeController ()

@property (nonatomic, strong) UIButton    *rightBarButtonItem;
@property (strong, nonatomic) UITableView *tableView;
@property (strong, nonatomic) BNDHomeCardHelper *helper;

@end

@implementation BNDHomeController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = UIColorWithHex(0xf5f5f5);
    self.title = @"卡片列表";
  //  [BNDOfficeDocHandle bndRegisterInfo:@"00ptbnd1908018713159904060714715" openId:@"00ptbnd1962460793159946082614215" token:@"1"];
    
    if([BNDPreference sharedInstance].companyOpenId.length>0&&[BNDPreference sharedInstance].token.length>0&&[BNDPreference sharedInstance].openId.length>0){
        
    }else{
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"请先初始化BNDOfficeDocHandlend的bndRegisterInfo方法" preferredStyle:UIAlertControllerStyleAlert];
        @weakify(self)
        UIAlertAction *confirm = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            @strongify(self)
            [self.navigationController popViewControllerAnimated:YES];
        }];
        [alert addAction:confirm];
        [self presentViewController:alert animated:true completion:nil];
        return;
    }
    
  
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.rightBarButtonItem];
    //    [BNDPreference sharedInstance].companyOpenId = @"00ptbnd1908018713159904060714715";
    //    [BNDPreference sharedInstance].openId = @"00ptbnd1962460793159946082614215";
    
    //TODO: 必传公司id和用户id
    //    [BNDPreference bndRegisterInfo:@"00ptbnd1908018713159904060714715" openId:@"00ptbnd1962460793159946082614215"];
  
    
    [self handleLoadList];
    
}


- (UIButton *)rightBarButtonItem
{
    if (_rightBarButtonItem == nil) {
        _rightBarButtonItem = [UIButton buttonWithType:UIButtonTypeCustom];
        _rightBarButtonItem.titleLabel.font = BNDPFHeavyFont(15);
        [_rightBarButtonItem lk_setTitle:@"进入公告"];
        [_rightBarButtonItem lk_setTextColor:UIColor.blackColor];
        [_rightBarButtonItem addTarget:self action:@selector(clickOfficeDocMethod) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _rightBarButtonItem;
}

#pragma mark - 处理列表

- (void)handleLoadList
{
    _tableView = [self createTableView];
    [self.view addSubview:_tableView];
    _helper = [[BNDHomeCardHelper alloc] initWith:_tableView];
    [_helper reload];
}

- (void)clickOfficeDocMethod
{
    BNDOfficeDocVc *vc = [[BNDOfficeDocVc alloc] init];
    [[BNDPushVCHandler currentSelectedNavController] pushViewController:vc animated:YES];
}




@end
